<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='edit'){
	$_SESSION['from_pluginname']=$_RQ['from_pluginname']?$_RQ['from_pluginname']:$_SESSION['from_pluginname'];
	$tabs=array(
			array('op'=>'edit','title'=>'商户编辑')
	);
	$item=pdo_get('jy_cmso2o_list',array('uniacid'=>$_SESSION['uniacid'],'pluginname'=>$_SESSION['from_pluginname']));
	if(!empty($item)){
		$item['lat_lng']=json_decode($item['lat_lng'],true);
		$item['onlinetime']=json_decode($item['onlinetime'],true);
		$item['location']=array('province'=>$item['province'],'city'=>$item['city'],'district'=>$item['district']);
	}
    $return['item']=$item;
	$return['group']=pdo_getall('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['ishow']=array('0'=>'不显示','1'=>'显示');
	$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
	$return['is']=array('0'=>'否','1'=>'是');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'设置',
		'tabs'=>$tabs,
		'edit'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'logo','type'=>'image'),
			array('name'=>'uid','title'=>'选择管理员','type'=>'choose_title','action'=>'get_member'),	
			
			array('name'=>'onlinetime','title'=>'营业时间','type'=>'time_hour'),
			array('name'=>'lat_lng','title'=>'坐标','type'=>'lat_lng'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'group_id','title'=>'分类','type'=>'select','options'=>'group'),
			array('name'=>'location','title'=>'地区','type'=>'pcd','options'=>'pcd'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'phone','title'=>'联系电话','type'=>'string'),
			array('name'=>'desc','title'=>'简介','type'=>'text'),
			array('name'=>'hdp','title'=>'幻灯片','type'=>'images'),
			//array('name'=>'ewm','title'=>'二维码','type'=>'image'),
			//array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			//array('name'=>'ishow','title'=>'是否显示','type'=>'radio','options'=>'ishow'),
			//array('name'=>'ishome','title'=>'是否首页显示','type'=>'radio','options'=>'is'),
			//array('name'=>'ishot','title'=>'是否热门','type'=>'radio','options'=>'is'),
			)
			);
	$return['pcd']=cfc('tools')->pcd();
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写标题','error');
	}
	if(!$postdata['uid']){
	//	exi('请选择管理员','');
	}
	if(!$postdata['logo']){
		exi('请上传logo','error');
	}
	if(!$postdata['address']){
		exi('请填写地址','error');
	}
	$data=array_fields(array('status','title','type','uid','logo','bgcolor','bgimg','onlinetime','group_id','url','image','ishome','lat_lng','address','price','phone','desc','ishot','ewm','ishot','ishow'),$postdata);
	$data['province']=$postdata['location']['province'];
	$data['district']=$postdata['location']['district'];
	$data['city']=$postdata['location']['city'];
	
	$data['onlinetime']=json_encode($data['onlinetime']);
	$data['lat_lng']=json_encode($data['lat_lng']);
	$data['hdp']=json_encode($data['hdp']);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_cmso2o_list',$data,array('id'=>$id));
		exi('修改成功！');
	}else{
		$data['pluginname']=$_SESSION['from_pluginname'];
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_cmso2o_list',$data);
		exi('创建成功！');
	}
}